package com.bw.controller;

import com.bw.entity.Dict;
import com.bw.entity.OrderInfo;
import com.bw.entity.OrderQuery;
import com.bw.mapper.OrderMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class OderController {


    @Autowired
    OrderMapper orderMapper;

    @RequestMapping("/list.do")
    public String list(OrderQuery query, Integer pageNum, Model model) {
        //渲染下拉框
        List<Dict> productTypeList = orderMapper.listProdectType();
        model.addAttribute("productTypeList", productTypeList);
        List<Dict> currencyTypeList = orderMapper.listCurrencyType();
        model.addAttribute("currencyTypeList", currencyTypeList);

        // 分页chax
        PageHelper.startPage(pageNum == null ?1:pageNum,3);
        List<OrderInfo> list = orderMapper.selectAll(query);
        PageInfo<OrderInfo> pageInfo = new PageInfo<>(list);


        model.addAttribute("pageInfo",pageInfo);

        //条件不丢失
        model.addAttribute("query",query);

        return "list";
    }

}
